
CROSS_COMPILE_PREFIX = 
MODE := DEBUG

SRC_DIR :=.
TMP_DIR :=obj

USER_BIN_NAME := out.elf
SRCS :=.
INC_PATH :=.

SRCS+=./demo
SRCS+=./demo/lv_ui
SRCS+=./demo/lv_ui/fonts
SRCS+=./demo/lv_ui/images
SRCS+=./demo/lv_ui/screens
SRCS+=./demo/porting

INC_PATH+=lvgl
INC_PATH+=demo
INC_PATH+=./demo/lv_ui
INC_PATH+=./demo/lv_ui/fonts
INC_PATH+=./demo/lv_ui/images
INC_PATH+=./demo/lv_ui/screens
INC_PATH+=./demo/porting

# SRC_FILES := $(foreach dir, $(SRCS), $(warning dir is: $(dir), wildcard is $(wildcard $(dir)/*.c))   $(wildcard $(dir)/*.c))
SRC_FILES := $(foreach dir, $(SRCS), $(wildcard $(dir)/*.c))
TMP_FILES := $(patsubst $(SRC_DIR)/%,$(TMP_DIR)/%, $(SRC_FILES)) # patsubst返回被替换过后的字符串
OBJ_FILES := $(TMP_FILES:.c=.o)
DEP_FILES := $(OBJ_FILES:.o=.d)

# $(warning SRC_FILES : $(SRC_FILES))
# $(warning OBJ_FILES : $(OBJ_FILES))

#FLAGS := -Wall -Werror
FLAGS :=
FLAGS += $(addprefix -I ,$(INC_PATH))
FLAGS += -std=gnu99

ifeq ($(MODE), DEBUG)
FLAGS += -g -MMD
else
FLAGS += -O2 -DNDEBUG
endif

LDFLAGS += lib/SDL2.dll
LDFLAGS += lib/liblvgl.a

LDFLAGS += -Wl,--copy-dt-needed-entries -lpthread -lm 

.PHONY : all clean

all : $(USER_BIN_NAME)

# @echo -e 'target: $@, deps: $^ '
# @echo -e 'target: $@, deps: $^, flag: $(FLAGS) '
$(TMP_DIR)/%.o: $(SRC_DIR)/%.c
	$(shell if [ ! -d $(dir $@) ];then mkdir -p $(dir $@); fi)
	@$(CROSS_COMPILE_PREFIX)gcc -c -o $@ $(FLAGS) $< 
	@echo -e '\033[32m"compiling gcc" : $<\033[0m'


-include $(DEP_FILES)
$(USER_BIN_NAME) : $(OBJ_FILES)
	$(shell if [ ! -d $(dir $@) ];then mkdir -p $(dir $@); fi)
	$(CROSS_COMPILE_PREFIX)gcc -o $@ $^ $(LDFLAGS)

	
clean :
	@echo -e '\033[32m"clean"\033[0m'
	@rm -rf $(shell find -name "*.o")
	@rm -rf $(shell find -name "*.d")
	@rm -rf $(USER_BIN_NAME)
	

